<?php

namespace Bean\Flow\RssFlow;

class Item extends \Bean\Flow\GenericFlow\Item {

	private $_node;
	private $_publicationTime;
	private $_itemId;
	private $_title;
	private $_description;
	private $_flow;
	private $_link;
	
	public function __construct( \DOMNode $node, \Bean\Flow\GenericFlow $flow ) {
		parent::__construct();
		$this->_node = $node;
		$this->_flow = $flow;
		
		foreach( $node->childNodes as $child ) {
			if( !$child instanceof \DOMNode ) {
				continue;
			}
			switch( mb_strtolower( $child->tagName ) ) {
				case 'pubdate':
					$this->_publicationTime = strtotime( trim($child->nodeValue) );
					break;
				case 'title':
					$this->_title = trim($child->nodeValue);
					break;
				case 'description':
					$this->_description = preg_replace( '/(\s\n)+/', "\n", trim($child->nodeValue) );
					break;
				case 'guid':
					$this->_itemId = trim($child->nodeValue);
					break;
				case 'link':
					$this->_link = trim($child->nodeValue);
					break;
			}
		}
	}
	
	public function getFlow() {
		return $this->_flow;
	}
	
	public function getTitle() {
		return $this->_title;
	}
	
	public function getMessage() {
		return $this->_title;
	}
	
	public function getLink() {
		return $this->_link;
	}
	
	public function getDescription() {
		return $this->_description;
	}

	public function getUser() {
		return $this->_flow->getUser();
	}
	
	public function getPublicationTime() {
		return $this->_publicationTime;
	}
	
	public function getItemId() {
		return $this->_itemId;
	}
	
	public function getView() {
		return 'Widget/Flow/RssFlow/Item';
	}
}
